<template>
	<view
		:style="'order:'+item.order+';'+item.css"
		class="my-mark-post">
		<template v-if="$_isLogin()">
			<template v-if="listStatus == 'success'">
				<view
					@click="$_to('post/detail?pid=' + item.pid)"
					v-for="(item, index) in list" :key="index"
					class="for">
					<view :class="item.commentCount === 0?'left':'left hover'">
						<view>{{item.commentCount}}</view>
						<view>{{$t('contentTopComment')}}</view>
					</view>
					<view class="right">
						<view class="title">
							{{item.title?item.title:$_filterHtml(item.content)}}
						</view>
						<view class="info">
							<view class="user">
								<view><image :src="item.author.avatar" mode="widthFix"></image></view>
								<text>{{item.author.nickname?item.author.nickname:$t('contentAuthorAnonymous')}}</text>
							</view>
							<view class="time">{{item.createdTimeAgo}}</view>
							<view class="group" v-if="item.group">
								<template v-if="item.group.parentGid">
									<text>{{item.group.parentInfo.name}}</text>
									<text class="iconfont icon-arrow-right"></text>
								</template>
								<text>{{item.group.name}}</text>
							</view>
						</view>
					</view>
					<view class="right-button">
						<template v-if="markType === 'follow'">
							<view @click.stop="clickMarkPostButton(item.pid)">
								<text class="iconfont icon-favorite"></text>
							</view>
						</template>
						<template v-if="markType === 'like'">
							<view @click.stop="clickMarkPostButton(item.pid)">
								<text class="iconfont icon-good"></text>
							</view>
						</template>
					</view>
				</view>
				<view
					class="more-content"
					@click="clickMoreButton">
					{{listPageText}}
				</view>
			</template>
			<template v-if="listStatus == 'loading'">
				<view class="_loading">
					<view class="left">
						<view class="skeleton-screen"></view>
					</view>
					<view class="right">
						<view class="skeleton-screen"></view>
					</view>
				</view>
			</template>
			<template v-if="listStatus == 'empty'">
				<view class="_empty">
					<view>
						<text class="iconfont icon-cry"></text>
						<text class="_text">
							<template v-if="markType === 'like'">
								暂无点赞
							</template>
							<template v-if="markType === 'dislike'">
								暂无点踩
							</template>
							<template v-if="markType === 'follow'">
								暂无收藏
							</template>
							<template v-if="markType === 'block'">
								暂无屏蔽
							</template>
						</text>
					</view>
				</view>
			</template>
		</template>
		<template v-else>
			<view class="no-login">
				<view>未登录，请登录</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		name:"my-mark-post",
		props:{
			item:{
				type:Object,
				default:null
			}
		},
		data() {
			return {
				list:[],
				listStatus:"loading",
				listPage:2,
				listPageText: this.$t('clickToLoadMore'),
				userUid:"",
				markType:this.item.markType
			};
		},
		mounted(){
			this.userUid = JSON.parse(uni.getStorageSync('accountAuthToken')).uid;
			this.getList();
		},
		methods: {
			getList(){
				this.$_request(
					"GET", `/api/fresns/v1/user/${this.userUid}/mark/${this.item.markType}/posts`,
					{
						"filterType":"whitelist",
						"filterKeys":"pid,commentCount,title,content,author.avatar,author.nickname,createdTimeAgo,group",
						"filterGroupType":"whitelist",
						"filterGroupKeys":"parentGid,parentInfo,name",
						"page":1
					},
					(res) => {
						if (res.data.data.list.length) {
							this.list = res.data.data.list;
							this.listStatus = "success";
						} else {
							this.listStatus = "empty";
						}
					}
				)
			},
			clickMoreButton(){
				if (this.listPageText == this.$t('loading')) { return }
				this.listPageText = this.$t('loading');
				this.$_request(
					"GET", `/api/fresns/v1/user/${this.userUid}/mark/${this.item.markType}/posts`,
					{
						"filterType":"whitelist",
						"filterKeys":"pid,commentCount,title,content,author.avatar,author.nickname,createdTimeAgo,group",
						"filterGroupType":"whitelist",
						"filterGroupKeys":"parentGid,parentInfo,name",
						"page": this.listPage
					},
					(res) => {
						if (res.data.data.list.length) {
							this.list = this.list.concat(res.data.data.list);
							this.listPage++
							this.listPageText = this.$t('clickToLoadMore')
						} else {
							this.listPageText = this.$t('listEmpty')
						}
					}
				)
			},
			clickMarkPostButton(pid){
				uni.showLoading();
				this.$_request(
					"POST","/api/fresns/v1/user/mark",
					{
						"markType":this.item.markType,
						"type":"post",
						"fsid":pid
					},
					(res) => {
						uni.hideLoading();
						if(res.data.code == 0 ){
							this.getList();
							this.listPage = 2;
							this.listPageText = this.$t('clickToLoadMore');
						}else{
							uni.showToast({
								title: res.data.message,
								icon: 'none',
								duration: 1500
							});
						}
					}
				)
			},
		},
	}
</script>

<style lang="scss" scoped>
.my-mark-post{
	padding: 0 25rpx;
	background: #FFF;
	.no-login{
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 25rpx;
		view{
			display: flex;
			align-items: center;
			justify-content: center;
			border: 1px solid $border;
			background: $background;
			padding: 25rpx 0;
			width: 100%;
		}
	}
	.more-content{
		padding: 25rpx 0;
		font-size: 22rpx;
		line-height: 22rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: $placeholder;
	}
	._empty{
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 25rpx 0;
		view{
			display: flex;
			align-items: center;
			justify-content: center;
			flex-flow: column;
			text{
				color: $placeholder;
			}
			.iconfont{
				font-size: 100rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				line-height: 100rpx;
			}
			._text{
				font-size: 28rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				line-height: 28rpx;
				padding-top: 25rpx;
			}
		}
	}
	._loading{
		display: flex;
		align-items: center;
		border-bottom: 1px solid $border;
		padding: 25rpx 0;
		.left{
			width: 80rpx;
			height: 80rpx;
			view{
				width: 80rpx;
				height: 80rpx;
				border-radius: 10rpx;
			}
		}
		.right{
			flex: 1;
			height: 80rpx;
			margin-left: 20rpx;
			border-radius: 10rpx;
			view{
				width: 100%;
				height: 80rpx;
			}
		}
	}
	.for{
		display: flex;
		align-items: center;
		border-bottom: 1px solid $background;
		padding: 25rpx 0;
		.left{
			width: 80rpx;
			height: 80rpx;
			display: flex;
			overflow: hidden;
			flex-flow: column;
			align-items: center;
			justify-content: center;
			margin-right: 20rpx;
			background: $background;
			border-radius: 10rpx;
			view{
				font-size: 22rpx;
				line-height: 22rpx;
				text-align: center;
			}
			view:nth-child(1){
				padding-bottom: 5rpx;
			}
		}
		.hover{
			background: $theme;
			view{
				color: #FFF;
			}
		}
		.right{
			flex: 1;
			height: 80rpx;
			display: flex;
			flex-flow: column;
			justify-content:center;
			.title{
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 1;
				overflow: hidden;
				font-size: 28rpx;
				line-height: 28rpx;
			}
			.info{
				display: flex;
				align-items: center;
				padding-top: 10rpx;
				.user{
					display: flex;
					align-items: center;
					view{
						width: 28rpx;
						height: 28rpx;
						border-radius: 100%;
						overflow: hidden;
					}
					text{
						padding: 0 0 0 10rpx;
						color: $darkBlue;
						font-size: 22rpx;
						line-height: 22rpx;
						flex-shrink: 0;
					}
				}
				.time{
					padding: 0 0 0 15rpx;
					color: $placeholder;
					font-size: 22rpx;
					line-height: 22rpx;
					flex-shrink: 0;
				}
				.group{
					padding: 0 0 0 15rpx;
					line-height: 22rpx;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					overflow: hidden;
					text{
						color: $placeholder;
						font-size: 22rpx;
					}
					.icon-arrow-right{
						font-size: 18rpx;
						padding: 0 5rpx;
					}
				}
			}
		}
		.right-button{
			flex-shrink: 0;
			view{
				width: 80rpx;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: $background;
				line-height: 50rpx;
				text{
					font-size: 50rpx;
					color: $red;
				}
			}
		}
	}
}
</style>